// EDVariable.cpp: implementation of the EDVariable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"
#include "EDVariable.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

EDVariable::EDVariable()
{
	this->m_strName = _T ( "" );
	this->m_bOwnExp = TRUE;
	this->m_pExpression = NULL;
}

EDVariable::EDVariable ( const EDVariable& var )
{
	if ( this != &var )
	{
		this->m_strName = var.m_strName;
		this->m_bOwnExp = TRUE;
		if ( var.m_pExpression )
		{
			this->m_pExpression = new EDSQLExpression;
			*this->m_pExpression = *var.m_pExpression;
		}
		else
		{
			this->m_pExpression = NULL;
		}
	}
}

EDVariable::EDVariable ( const CString& strName, const CString& strExp ) :
	m_strName ( strName ), m_pExpression ( new EDSQLExpression ( strExp ) )
{
}

EDVariable& EDVariable::operator = ( const EDVariable& var )
{
	if ( this == &var )
		return *this;

	this->m_strName = var.m_strName;
	this->m_bOwnExp = TRUE;
	if ( var.m_pExpression )
	{
		if ( m_pExpression == NULL )
			m_pExpression = new EDSQLExpression;
		*m_pExpression = *var.m_pExpression;
	}
	else
	{
		if ( this->m_pExpression )
		{
			delete m_pExpression;
			m_pExpression = NULL;
		}
	}

	return *this;
}

EDVariable::~EDVariable()
{
	if ( this->m_pExpression && m_bOwnExp )
	{
		delete this->m_pExpression;
		this->m_pExpression = NULL;
	}
}
